import {
  Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, Input, Output,
  EventEmitter, ElementRef, ViewChildren, QueryList
} from '@angular/core';

import {GoodsButtonComponent} from "@goods/components/goods-button/goods-button.component";
import {GoodsAttributeRespVO, GoodsRespVO} from "@interface/index";
import {TicketSkuDetailVO} from "../../../../interface/goods/goods.model";


@Component({
  selector: 'seed-ticket-spec-item',
  templateUrl: './ticket-spec-item.component.html',
  styleUrls: ['./ticket-spec-item.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class TicketSpecItemComponent implements OnInit {
  // public index;
  public current: number;
  public item: GoodsAttributeRespVO;
  public attrCode;
  public _disabled = false;
  public _row: number;
  @Input() goods: TicketSkuDetailVO;
  @Input() goodsAttributes: GoodsAttributeRespVO;
  @ViewChildren(GoodsButtonComponent) goodsButtons: QueryList<GoodsButtonComponent>;

  @Input()
  set row(val) {
    this._row = val;
  }

  get row() {
    return this._row;
  }

  @Output() onSelected: EventEmitter<GoodsAttributeRespVO> = new EventEmitter<GoodsAttributeRespVO>();

  constructor(public ele: ElementRef) {
  }

  set isDisabled(val: boolean) {
    this._disabled = val;
  }

  get isDisabled(): boolean {
    return this._disabled;
  }

  handleChangeSpec(item, idx) {
    if (this.current === idx) {
      return;
    }
    this.item = item;
    this.item['row'] = this.row;
    this.current = idx;
    this.attrCode = item.attrCode;
    this.onSelected.emit(this.item);
  }


  ngOnInit() {
  }

}
